package com.woniuxy.rms.service.impl;

import com.woniuxy.rms.dao.HotlistMapper;
import com.woniuxy.rms.pojo.Hotlist;
import com.woniuxy.rms.service.HotService;
import com.woniuxy.rms.util.DataResult;
import com.woniuxy.rms.util.HotTypeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Auther: chengang  <br/>
 * Date: 2020/3/28 0028:上午 10:50  <br/>
 * Description:活动服务层
 */
@Service
public class HotServiceImpl implements HotService {

    @Autowired
    HotlistMapper hotlistMapper;

    @Override
    public List<Hotlist> findByPage(Integer currentPage, Integer pageSize, Integer status, Integer roleId) {
        List<Hotlist> re = null;
        if (roleId == null){
            //查询用户发布的活动
            roleId = HotTypeUtil.USER.getHotType();
            List<Hotlist> user = hotlistMapper.findUserByPage(currentPage,pageSize,status,roleId);
            //查询商户发布的活动
            roleId = HotTypeUtil.VENTOR.getHotType();
            List<Hotlist> vendor = hotlistMapper.findVendorByPage(currentPage,pageSize,status,roleId);
            //查询物业发布的活动
            roleId = HotTypeUtil.PROPERTY.getHotType();
            List<Hotlist> pro = hotlistMapper.findProByPage(currentPage,pageSize,status,roleId);
            //合并
            user.addAll(vendor);
            user.addAll(pro);
            return user;
        }else {
            if (roleId.equals(HotTypeUtil.PROPERTY.getHotType())){//物业类型
                return hotlistMapper.findProByPage(currentPage,pageSize,status,roleId);
            }
            if (roleId.equals(HotTypeUtil.USER.getHotType())){//用户类型
                return hotlistMapper.findUserByPage(currentPage,pageSize,status,roleId);
            }
            if (roleId.equals(HotTypeUtil.VENTOR.getHotType())){//商户类型
                return hotlistMapper.findVendorByPage(currentPage,pageSize,status,roleId);
            }
        }
        return re;
    }

    @Override
    public DataResult hotStatus(Long id, Integer status) {
        hotlistMapper.check(id,status);
        return DataResult.success();
    }
}